home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / AppleScanGS / Utils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-03  |  5.6 KB  |  247 lines  |  [TEXT/MPS ]

  1. #include <gsos.h>
  2. #include <quickdraw.h>
  3. #include <qdaux.h>
  4. #include <window.h>
  5. #include <MiscTool.h>
  6. #include <texttool.h>
  7. #include <malloc.h>
  8. #include "scan.h"
  9. /* include the following line to use Tool039
  10.  * #include "scToolSet.h"
  11.  */
  12. char    test[80];
  13.  
  14. #if 0
  15.  
  16. /**********************************************************************/
  17.  
  18. void    pdlWait()
  19. {
  20.     unsigned int    i;
  21.  
  22.     for (;;) {
  23.         GrafOff();
  24.         for (;;) {
  25.             for (i = 2; i; i--) {
  26.                 if (*((char *)(0xE0C060 + i)) & 0x80) break;
  27.             }
  28.             if (i) break;
  29.         }
  30.         GrafOn();
  31.         for (; *((char *)(0xE0C060 + i)) & 0x80;) {
  32.             if (*((char *)(0xE0C063 - i)) & 0x80) return;
  33.         }
  34.         if (i == 1) return;
  35.     }
  36. }
  37.  
  38. /**********************************************************************/
  39.  
  40. void    sbug(str)
  41. char    *str;
  42. {
  43.     if (*((char *)0xE0C061) >= 0x80) return;
  44.     InitTextDev(1);
  45.     WriteCString(str);
  46.     pdlWait();
  47. }
  48.  
  49. /**********************************************************************/
  50.  
  51. void    stack()
  52. {
  53.     unsigned int    stk;
  54.  
  55.     asm {
  56.         tsc
  57.         sta stk
  58.     }
  59.     sprintf(test, "stack=%X", stk);
  60.     sbug(test);
  61. }
  62.  
  63. #endif
  64.  
  65. asm (SwapBytes) {
  66.     lda 4,s
  67.     xba
  68.     rtl
  69. }
  70.  
  71. asm (SwapWords) {
  72.     lda 4,s                /* swap the words, and swap the bytes inside of those words */
  73.     xba
  74.     tax
  75.     lda 6,s
  76.     xba
  77.     rtl
  78. }
  79.  
  80. /*********************************************************************************************/
  81.  
  82. long doScan(bufferHandle, bufferSize, sWindowDef, Width, Length)
  83. Handle            bufferHandle;
  84. unsigned long    bufferSize, Width, Length;
  85. scannerWindowDef *sWindowDef;
  86. {
  87.     extern Long (*Setup[])();
  88.     unsigned long requestCount, transferCount;
  89.  
  90.     Scanner_Open();
  91.     
  92.     transferCount = (*Setup[Scanner_Type])(bufferHandle, bufferSize, sWindowDef, Width, Length);
  93.     
  94.     Scanner_Close();
  95.     return(transferCount);
  96. }
  97.  
  98. long Setup_Apple(bufferHandle, bufferSize, sWindowDef, Width, Length)
  99. Handle            bufferHandle;
  100. unsigned long    bufferSize, Width, Length;
  101. scannerWindowDef *sWindowDef;
  102. {
  103.     unsigned long requestCount, transferCount;
  104.     Scanner_SetMode();
  105.     Scanner_SetHalfTones();
  106.     Scanner_DefWindow(sWindowDef);
  107.     Scanner_Scan();
  108.     
  109.     transferCount = Scanner_Read(*bufferHandle, bufferSize);
  110.  
  111.     return(transferCount);
  112. }
  113.  
  114. long Setup_CPCScan(bufferHandle, bufferSize, sWindowDef, Width, Length)
  115. Handle            bufferHandle;
  116. unsigned long    bufferSize, Width, Length;
  117. scannerWindowDef *sWindowDef;
  118. {
  119.     unsigned long requestCount, transferCount;
  120.     
  121.     transferCount = CPC_Scan(*bufferHandle, bufferSize, Width, Length);
  122.  
  123.     return(transferCount);
  124. }
  125.  
  126. #ifndef __scToolSet__    /* original version */
  127. int findScanner()
  128. {
  129.     int            retcode = 1;        /* assume we're gonna find a scanner */
  130.     char        cmdData[16];        /* need 16 bytes for Command Data list */
  131.     ResultBuf32    devName;
  132.     DInfoRecGS    devInfo;
  133.     DAccessRecGS devStatus;
  134.     extern int    scanDevnum;
  135.  
  136.     devInfo.pCount = 8;    /* we need the device ID */
  137.     devInfo.devNum = 1;    /* start at the first device */
  138.     devInfo.devName = &devName;
  139.     devName.bufSize = 36;
  140.  
  141.     scanDevnum = 0;        /* initialize scanner device number */
  142.  
  143.     DInfoGS(&devInfo);    /* make the call */
  144.     while(!_toolErr) {    /* continue until we run out of devices */
  145.         if(devInfo.deviceID == 0x001a) {    /* is this a SCSI scanner? */
  146.             scanDevnum = devInfo.devNum;    /* yes, save the device number */
  147.             break;                            /* and exit */
  148.         }
  149.         ++devInfo.devNum;                    /* check the next device */
  150.         DInfoGS(&devInfo);
  151.     }
  152.     if(_toolErr && (_toolErr != 0x11)) {
  153.         InitCursor();
  154.         ErrorWindow(0,NULL,_toolErr);
  155.         WaitCursor();
  156.     }
  157.  
  158.     if(!scanDevnum) {
  159.         InitCursor();
  160.         retcode = AlertWindow(4, NULL, (long) noScannerFound);
  161.         WaitCursor();
  162.     } else {    /* we have a scanner DIB, let's make sure it's ready for us */
  163.         devStatus.pCount = 5;    /* set up for DStatus call */
  164.         devStatus.devNum = scanDevnum;
  165.         devStatus.code = 0x8000;    /* TestUnitReady status call */
  166.         devStatus.list = (Ptr) cmdData;
  167.         memset(cmdData,0,16);        /* set to all zeros */
  168.         devStatus.requestCount = 0;    /* not used for this call */
  169.         DStatusGS(&devStatus);
  170.         while(_toolErr) {    /* if we get an error, let the user know */
  171.             InitCursor();
  172.             retcode = AlertWindow(4, NULL, (long) scannerNotReady);
  173.             WaitCursor();
  174.             if(!retcode) /* user clicked QUIT */
  175.                 break;
  176.             else if(retcode == 2) {    /* user clicked "Continue" */
  177.                 scanDevnum = 0;    /* pretend we didn't find a scanner */
  178.                 break;
  179.             } else {    /* user clicked on "Try Again" */
  180.                 DStatusGS(&devStatus);    /* do the status call again */
  181.                 DStatusGS(&devStatus);    /* and again to make sure the SCSI bus is initialized */
  182.             }
  183.         }
  184.     }
  185.     
  186.     return(retcode);
  187. }
  188.  
  189. #else    /* new version which uses the toolset */
  190. int findScanner()
  191. {
  192.     int            retcode = 1;        /* assume we're gonna find a scanner */
  193.     extern int    scanDevnum;
  194.  
  195.     scanDevnum = 0;        /* initialize scanner device number */
  196.  
  197.     /* start up the toolset here */
  198.     scStartUp();    
  199.  
  200.     switch(_toolErr) {
  201.         case 0:    /* no error */
  202.             scanDevnum = scGetDevNum();    /* get the device number from the toolset */
  203.             break;
  204.         
  205.         case scNotFoundErr:
  206.             InitCursor();
  207.             retcode = AlertWindow(4, NULL, (long) noScannerFound);
  208.             WaitCursor();
  209.             break;
  210.  
  211.         case scScannerErr:
  212.             while(_toolErr) {    /* if we get an error, let the user know */
  213.                 InitCursor();
  214.                 retcode = AlertWindow(4, NULL, (long) scannerNotReady);
  215.                 WaitCursor();
  216.                 if(!retcode) /* user clicked QUIT */
  217.                     break;
  218.                 else if(retcode == 2) {    /* user clicked "Continue" */
  219.                     scanDevnum = 0;    /* pretend we didn't find a scanner */
  220.                     break;
  221.                 } else {    /* user clicked on "Try Again" */
  222.                     scStartUp();    /* so try to start up the toolset again */
  223.                 }
  224.             }
  225.             break;
  226.  
  227.         default:
  228.             InitCursor();
  229.             ErrorWindow(0,NULL,_toolErr);
  230.             WaitCursor();
  231.     }
  232.  
  233.     return(retcode);
  234. }
  235.  
  236. #endif
  237.  
  238. void testPause()
  239. {
  240.     
  241.     SysBeep(); SysBeep();
  242.     while (*(char *) 0xe0c000 < 128)
  243.         ;
  244.     *(char *) 0xe0c010 = 0;
  245. }
  246.  
  247.